﻿package ygg.printer
{
	import j.sus2maj7.printer.*;
	import j.sus2maj7.context.*;
	import j.sus2maj7.util.*;
	import flash.utils.ByteArray;
	
	import ygg.encoding.swf.abc.*;
	import ygg.encoding.swf.abc.object.*;
	import ygg.encoding.swf.abc.constant.*;
	
	public class ConstantPrinter extends TraitPrinter
	{
		
		public function ConstantPrinter()
		{
			super();
		}
		override public function printToString(o:*, context:IContext=null):String
		{
			return printToStringB(o, context).toString();
		}
		override public function printToStringB(o:*, context:IContext=null):StringBuilder
		{
			return print(Constant(o), PrinterContext(context) );
		}
		private function print(o:Constant, pc:PrinterContext ):StringBuilder
		{//trace('cnst print');
			//var cPool:ConstantPool = context.constantPool;
			var sb:StringBuilder = (pc.sb == null) ? new StringBuilder() : pc.sb;
			var indent:String = pc.indent || '';
			//var tab:String = pc.tab || '    ';
			
			if (o.metadata)
			{
				sb.append('\n');
				var md:*;
				for each (md in o.metadata)
				{
					sb.append(indent + md + "\n"+indent)
				}
			}
			
			sb.append(((o.isStatic)? 'static ' :''));
			sb.append(o.accessSpecifier + ' const ' + o.name + ":" + o.type);
			
			sb.append((o.value !== undefined ? (" = " + (o.value is String ? ('"' + o.value + '"') : o.value)) : "") +';' );
			sb.append( " // slot_id " + o.id + "\n"+ indent);
			
				
			
			return sb;
			
		}
	}
}